using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace SpoonCore.Storage.Item
{
	class StringStorageItem : AbstractStorageItem
	{
		private string _value = "";

		public StringStorageItem()
		{ }

		public StringStorageItem(SpoonIdentifier id, string value)
			: base(id)
		{
			_value = value;
		}

		public string Value
		{
			get { return _value; }
			set { _value = value; }
		}

		public override byte[] GetBytes()
		{
			MemoryStream stream = new MemoryStream();
			BinaryWriter bw = new BinaryWriter(stream);
			bw.Write(_value);
			return stream.ToArray();
		}

		public override void SetBytes(byte[] data)
		{
			BinaryReader br = new BinaryReader(new MemoryStream(data));
			_value = br.ReadString();
		}
	}
}
